package features.advance.leetcode.geometry.doublepointer.easy;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ListNode {

       public int val;
       public ListNode next;
       public ListNode(){}
       public ListNode(int x){
            val = x;
        }
        public ListNode(int x,ListNode next){
           this.val = x;
           this.next = next;

        }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ListNode listNode = (ListNode) o;
        return val == listNode.val &&
                Objects.equals(next, listNode.next);
    }

    @Override
    public int hashCode() {
        return Objects.hash(val, next);
    }

    @Override
    public String toString() {
           List list = new ArrayList<>();
           recursion(this,list);
           return list.toString();
    }

    private ListNode recursion(ListNode listNode,List list){
           if(listNode == null){
               return null;
           }
           list.add(listNode.val);
           return recursion(listNode.next,list);
    }
}
